local ngx = ngx
local require = require
local uu = require('modules.commhm.utils')
local log = require("modules.commhm.log");
local FOO = {
    _VERSION = '0.0.1'
}

-- 最小版本限制
FOO.version_min_check = function(minVer, ver)
    ver = ver or ngx.ctx.m_params.ver
    return uu.ver2i(minVer) <= uu.ver2i(ver)
end

--最大版本限制
FOO.version_max_check = function(maxVer, ver)
    ver = ver or ngx.ctx.m_params.ver
    return uu.ver2i(maxVer) >= uu.ver2i(ver)
end

-- !@ 是否ssdb的校验数据
FOO.is_ssdb_pin = function(code)
    local  pin_codes = {_h_ = true, _t_ = true, _k_ = true}
    return pin_codes[code] or false
end

FOO.real_client_ip = function ()
    -- ma 网关按逗号作为分隔符拼接了整个请求的代理链路
    local xff = ngx.req.get_headers()["X-Forwarded-For"]
    log.debug("xff="..(xff or "nil") .."|remote_addr=".. (ngx.var.remote_addr or "nil"))
    return xff and uu.split(xff, ',')[1] or ngx.var.remote_addr
end

return FOO